package com.da.javatest.niuke.baodian;

/**
 * @author chenlida
 * @date 2020/10/17 23:57
 * https://www.nowcoder.com/practice/1a002eed40054042867eb1aa5b98fb11?tpId=8&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C76Distance {
    public int getDistance(String[] article, int n, String x, String y) {
        int distance = Integer.MAX_VALUE;
        int s1 = 0, s2 = 0;
        for (int i = 0; i < article.length; i++) {
            if (article[i].equals(x)) {
                s1 = i;
                if (s1 != 0 && s2 != 0) {
                    distance = Math.min(distance, Math.abs(s1 - s2));
                }
            }
            if (article[i].equals(y)) {
                s2 = i;
                if (s1 != 0 && s2 != 0) {
                    distance = Math.min(distance, Math.abs(s1 - s2));
                }
            }
        }

        return distance;
    }
}
